using System.Collections.Generic;

using com.tc.zigbee.zcl;

using com.tc.util;
namespace com.tc.zigbee.zcl.command
{
    public class ReadAttributeResponse : AbstractZclCommand
    {
        public List<AttributeRecord> getAttributes()
        {
            return attributes;
        }
        List<AttributeRecord> attributes = new List<AttributeRecord>();
        public ReadAttributeResponse(byte[] data)
        {
            int i = 0;
            while (i < data.Length)
            {

                byte[] ai = new byte[2];
                ai[0] = data[i++];
                ai[1] = data[i++];
                short aii = DataUtil.shortValue(ai);
                byte status = data[i++];
                DataValue dv = null;
                if (status == 0)
                {
                    byte dt = data[i++];
                    DataType dtt = DataTypeManager.types[dt];
                    byte[] value = new byte[dtt.getLength()];
                    for (int j = 0; j < dtt.getLength(); j++)
                    {
                        value[j] = data[i++];
                    }
                    dv = new DataValue(dt, value);

                }
                AttributeRecord ar = new AttributeRecord(aii, status, dv);
                attributes.Add(ar);
            }

        }
    }
}